home *** CD-ROM | disk | FTP | other *** search
- /*
- * the class PLACE_COMPONENT
- * Copyright (C) 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
- */
-
- #include "../stdafx.h"
-
- #include "../common/bool.h"
- #include "../resource.h"
- #include "plcomp.h"
- #include "plcmpdlg.h"
-
- #include "../record.h"
-
- void PLACE_COMPONENT::PLACE_COMPONENT_MOUSE_CURSOR::draw_cursor_core(KBAN_DRAW& draw, const XY& ac)
- {
- m_component.set_ac(ac);
- draw.draw_one_component_cursor(m_component, 0);
- }
-
- STAGE* PLACE_COMPONENT::init_new(KBAN_INFO& info, KBAN_DRAW& draw)
- {
- return new STAGE_INITIAL();
- }
-
- const char* PLACE_COMPONENT::get_name(void)
- {
- return "Place:Component";
- }
-
- PLACE_COMPONENT::STAGE_INITIAL::STAGE_INITIAL(void)
- {
- }
-
- STAGE *PLACE_COMPONENT::STAGE_INITIAL::init(KBAN_INFO& info, KBAN_DRAW& draw)
- {
- CPlaceCompDialog dialog(AfxGetMainWnd());
- STAGE* retval = NULL;
- if(dialog.DoModal() == IDOK) {
- CString comp_name = dialog.GetComponentName();
- CString designator = dialog.GetDesignator();
- COMPONENT_LIST& list = info.kban_data().component_list();
- // if(list.search_designator(designator) != NULL) {
- if(false) {
- AfxGetMainWnd()->MessageBox("The designator has already been in use", "Place Component");
- } else {
- FILE_NEW fp(comp_name, "r");
- if(!fp.is_ok()) {
- AfxGetMainWnd()->MessageBox("Cannot open the file", "Place Component");
- } else {
- COMPONENT_ELEMENT component;
- KBAN_DATA kban_data;
- kban_data.load(fp);
- component = kban_data.primitive();
- component.set_component_name(comp_name );
- component.set_designator (designator);
- retval = new STAGE_PLACE_COMPONENT(component);
- }
- }
- }
- return retval;
- }
-
- PLACE_COMPONENT::STAGE_PLACE_COMPONENT::STAGE_PLACE_COMPONENT(COMPONENT_ELEMENT& component)
- : m_mcur(m_component),
- m_component(component)
- {
- }
-
- STAGE* PLACE_COMPONENT::STAGE_PLACE_COMPONENT::redraw(KBAN_INFO& info, KBAN_DRAW& draw)
- {
- m_mcur.redraw_cursor(draw);
- return this;
- }
-
- STAGE* PLACE_COMPONENT::STAGE_PLACE_COMPONENT::key_in(KBAN_INFO& info, KBAN_DRAW& draw, UINT key, UINT nFlags)
- {
- switch(key) {
- case 'r' :
- case 'R' : {
- m_mcur.erase_cursor(draw);
- m_component.rotate_90();
- break;
- }
- }
- return this;
- }
-
- STAGE* PLACE_COMPONENT::STAGE_PLACE_COMPONENT::mouse_move(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
- {
- XY ac;
- info.grid().xy_pc2ac(pc, ac);
- m_mcur.draw_cursor(draw, ac);
- return this;
- }
-
- STAGE *PLACE_COMPONENT::STAGE_PLACE_COMPONENT::mouse_left_up(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
- {
- m_mcur.erase_cursor(draw);
-
- XY ac;
- info.grid().xy_pc2ac(pc, ac);
-
- COMPONENT_LIST& component_list = info.kban_data().component_list();
-
- m_component.set_ac(ac);
- draw.draw_one_component(m_component, info.active_layer().get());
- component_list.push_back(m_component);
- info.SetModifiedFlag();
- info.new_state().set(true);
- info.new_state_str() = "Place Component";
-
- return new STAGE_INITIAL;
- }
-
- STAGE *PLACE_COMPONENT::STAGE_PLACE_COMPONENT::mouse_right_up(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
- {
- return new STAGE_INITIAL;
- }
-
- void PLACE_COMPONENT::STAGE_PLACE_COMPONENT::end(KBAN_INFO& info, KBAN_DRAW& draw)
- {
- m_mcur.erase_cursor(draw);
- }
-